<?php

function _lib($name) {
	$filename = LIB_PATH.$name.".class.php";
	try {
		require_once($filename);
	} catch(Exception $e) {
		exit("Load class $name failed, err:".$e->getMessage());
	}
}

function _import($name) {
	$filename = UTIL_PATH.$name;
	try {
		require_once($filename);
	} catch (Exception $e) {
		exit("Load class $name failed, err:".$e->getMessage());
	}
}

function _error($msg, $type) {
	if( SYSTEM_MODE == DEBUG_MODE) {
		echo $msg;
	} else if( ERROR_FILE ){
		file_put_contents(ERROR_FILE, "$type error, $msg", FILE_APPEND);	
	} 
	if( $type == "fatal") {
		exit();
	}
}

// 将伪绝对路径变成真绝对路径 exam: /public/ => d:/xampp/htdocs/xx/public/
function _path($path) {
	$realpath = $_SERVER['DOCUMENT_ROOT'].$path;
	if( file_exists($realpath) ) {
		return $realpath;
	}
	return null;
}

function _print($val, $name = null) {
	echo $name."--";
	if($val == null) {
		echo 'null';
		return ;
	}
	if( is_array($val) ) {
		var_dump($val);
	} else {
		echo $val;
	}
	echo "<br/>";
}

function _step($val = null, $name = null) {
	_print($val, $name);
	exit("");
}

function ajaxDone($msg = '操作成功', $code = '200', $navTabId = '', 
			$rel = '', $callbacktype = '', $forwardUrl = '', $confirmMsg = '') {
	return '{
		"statusCode":'.$code.',
		"message":"'.$msg.'",
		"navTabId":"'.$navTabId.'",
		"rel":"'.$rel.'",
		"callbackType":"'.$callbacktype.'",
		"forwardUrl":"'.$forwardUrl.'",
		"confirmMsg":"'.$confirmMsg.'"
	}';	
}
